
var RenminderView = Backbone.View.extend({
    el:$('.reminLb'),
    template: _.template(templateLoader['reminder']),
    events:{
        'click .switchBtn': 'switchRem'
    },
    initialize:function(){
        this.config = {
            'c1':{
                label : '新股中签提醒',
                img : 'images/actx_07.png'
            },
            'c2':{
                label : '产品到期提醒',
                img : 'images/actx_11.png'
            },
            'c3':{
                label : '交易确认提醒',
                img : 'images/actx_13.png'
            },
            'c4':{
                label : '持仓股重要公告提醒',
                img : 'images/actx_16.png'
            },
            'c5':{
                label : '资金变动提醒',
                img : 'images/actx_18.png'
            }
        };
        this.listenTo(this.collection , 'add' , this.render);
        this.listenTo(this.collection , 'change' , this.dataChange);
    },
    dataChange:function(model){
        var cl = $('.switchBtn[rid="'+model.get('id')+'"]').parents('li');
        if(model.get('status')=='1'){
            cl.removeClass().find('.switchbg').css({'right':'20px','left':'none'}).animate({left:'40%',duration:200},function(){
                cl.addClass('remin-selected');
            });
        }else{
            cl.find('.switchbg').css({left:'40%','right':'none'}).animate({left:0,duration:200},function(){
                cl.removeClass('remin-selected');
            });
        }
    },
    render:function(model){
        this.$el.append(this.template(model.toJSON()));
    },
    switchRem:function(event){
        var _this = $(event.target);
        if(!_this.hasClass('switchBtn')){
            _this = _this.parent();
        }
        var rid = _this.attr('rid');
        reminderCollection.update(rid);
    }
});

var renminderView = new RenminderView({collection:reminderCollection});